#include "SystemSDL_1_3.h"
#include "MainWindowSDL_1_3.h"

#include <SDL.h>

SDL_RWops* g_stdout     = NULL;
SDL_RWops* g_stderr     = NULL;
const char* STDOUT_NAME = "..\\..\\Output\\data.htm";
const char* STDERR_NAME = "..\\..\\Output\\error.txt";

bool CSystemSDL_1_3::m_isRunning   = false;

CSystemSDL_1_3::CSystemSDL_1_3( void )
{
    //ctor
}

CSystemSDL_1_3::~CSystemSDL_1_3( void )
{
    //dtor
}

int CSystemSDL_1_3::Init( void )
{
    //  this stuff needs to initialized right away
    //  because other .cpp files depends on it.
    g_stdout = SDL_RWFromFile( STDOUT_NAME, "w" );

    if( g_stdout == NULL )
        printf( "Could not create stdout\n" );

    g_stderr = SDL_RWFromFile( STDERR_NAME, "w" );

    if( g_stderr == NULL )
        printf( "Could not create stderr\n" );

    return CSystemSDL_1_3_Main::Init();
}

int CSystemSDL_1_3::Process( void )
{
    // pump event loop
    return CSystemSDL_1_3_Main::ProcessEvents();

}

void CSystemSDL_1_3::Update( void )
{
    //CSystemSDL_1_3_Main::m_pMainWnd->Clear();
    CSystemSDL_1_3_Main::m_pMainWnd->Refresh();
}

void CSystemSDL_1_3::ShutDown( void )
{
    CSystemSDL_1_3_Main::ShutDown();

    if( g_stdout != NULL )
    {
        SDL_RWclose( g_stdout );
        g_stdout = NULL;
    }
    if( g_stderr != NULL )
    {
        SDL_RWclose( g_stderr );
        g_stderr = NULL;
    }
}

const char* CSystemSDL_1_3::GetError( void )
{
    return CSystemSDL_1_3_Helper::m_SysErrorMessage;
}
